package com.springboot.testcord.config;

import com.springboot.testcord.vo.ResultVo;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(NullPointerException.class)
    public ResultVo exception(NullPointerException exception) {
        return new ResultVo(500, "空指针异常",null);
    }

    @ExceptionHandler(IndexOutOfBoundsException.class)
    public ResultVo exception(IndexOutOfBoundsException exception) {
        return new ResultVo(500, "数组越界异常", null);
    }

    @ExceptionHandler(Exception.class)
    public ResultVo exception(Exception exception) {
        return new ResultVo(500, exception.getMessage(),null);
    }

}
